package com.erp.ae.controller;

import com.erp.ae.service.IAeCategoryService;
import com.erp.ae.service.IAeLogisticsService;
import com.erp.ae.utils.AeApiUtils;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.oldUtils.StringUtils;
import com.ruoyi.common.core.web.controller.BaseController;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Validated
@RequiredArgsConstructor
@RequestMapping("/ae/category")
@RestController
public class AeCategoryController extends BaseController {
    private final IAeCategoryService iAeCategoryService;

//	@RequestMapping(value = "getAliexpressCategoryResponseById", method = RequestMethod.POST)
//	public R<List<Map<String, String>>> getAliexpressCategoryResponseById(@RequestBody Map<String, List<Long>> map) {
//		List<Map<String, String>> aliexpressCategoryDatas = new ArrayList<>();
//		List<Long> ids = map.get("ids");
//		Long[] index = { 0L };
//		ids.forEach(id -> {
//			index[0]++;
//			System.out.println(String.format("index %s / %s", index[0], ids.size()));
//			String response = AeApiUtils.getchildattributesresultbypostcateidandpath(String.valueOf(id));
//			aliexpressCategoryDatas.add(new HashMap<String, String>() {
//				{
//					put("categoryId", String.valueOf(id));
//					put("response", response);
//				}
//			});
//		});
//		return R.ok("操作成功", aliexpressCategoryDatas);
//	}

    @RequestMapping(value = "getById")
    public R<String> getById(String categoryId) {
        return R.ok(iAeCategoryService.getById(categoryId));
    }

    @RequestMapping(value = "getByCategoryId/{categoryId}")
    public R<String> getByCategoryId(@PathVariable("categoryId") String categoryId) {
        return R.ok(iAeCategoryService.getById(categoryId));
    }

    @RequestMapping(value = "getBrandById")
    public String getBrandById(String categoryId, Long storeId) {
        return iAeCategoryService.getBrandById(categoryId, storeId);
    }

    @GetMapping(value = "getBrandByIdInnerAuth/{categoryId}/{storeId}")
    public R<String> getBrandByIdInnerAuth(@PathVariable("categoryId") String categoryId, @PathVariable("storeId") Long storeId) {
        String brandById = iAeCategoryService.getBrandById(categoryId, storeId);
        if (StringUtils.isEmpty(brandById)) {
            return R.fail(null);
        } else {
            return R.ok(brandById);
        }
    }
}
